home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Virtual User / Virtual User Current Release / Examples / Example Libraries / Gestalt.vulib < prev    next >
Encoding:
Text File  |  1998-06-04  |  16.0 KB  |  579 lines  |  [TEXT/MPS ]

  1. #
  2. #    File:            Gestalt.vulib
  3. #
  4. #    Contains:        Sample tasks for working with standard Gestalt calls.
  5. #                    For a more detailed description of these tasks, refer to
  6. #                    Virtual User Example Libraries reference document included
  7. #                    with the Virtual User 2.1 product.  This document contains
  8. #                    listings of all possible return values.
  9. #
  10. #    Requirements:    Gestalt support on target machine.  Note that the task
  11. #                    SetGestaltGlobals() needs to be called at the beginning
  12. #                    of every script that is to use the Gestalt.vulib library
  13. #                    of tasks.
  14. #
  15. #    Written by:    David Gaxiola, Phil Thompson, and Chad Williams
  16. #
  17. #    Copyright:    © 1992-96 by Apple Computer, Inc., all rights reserved.
  18. #
  19. #    Change History (most recent first):
  20. #
  21. #                 3/15/96    CMW        Updated for 2.1 format of Gestalt returned values.
  22. #                11/24/92    PRT        Modified some repetitive if-return statements,
  23. #                                    allowed more types for GetGestaltMachineType.
  24. #                 8/18/92    DGG        Added IsGestaltLongError task
  25. #                 8/12/92    DGG        EasyAccess GestaltTask modified
  26. #                  8/6/92    DGG        Some tasks modified to use bitwise operators.
  27. #                                    Gestalt's inability to report full 8 MB of
  28. #                                    physical memory.
  29. #                  8/4/92    DGG        Renamed all tasks.
  30. #                 7/22/92    DGG        Created.
  31. #
  32. #    To Do:
  33. #
  34.  
  35. (************************************************************************************
  36. * Task SetGestaltGlobals()
  37. *    Will set global variables of possible Gestalt error responses.
  38. ************************************************************************************)
  39. task SetGestaltGlobals()
  40. begin
  41.     global kGestaltNoErr := 0;
  42.     global kGestaltUnknownErr := -5550;
  43.     global kGestaltUndefSelectorErr := -5551;
  44. end;
  45.  
  46. (************************************************************************************
  47. * Task GestaltGetError(gestaltAnswer)
  48. *    Will return the error portion of a Gestalt call response.
  49. ************************************************************************************)
  50. task GestaltGetError(gestaltAnswer := {0,0})
  51. begin
  52.     return gestaltAnswer[1];
  53. end;
  54.  
  55. (************************************************************************************
  56. * Task GestaltGetLongError(gestaltAnswer)
  57. *    Will return a longer error response in the form of a string.
  58. ************************************************************************************)
  59. task GestaltGetLongError(gestaltAnswer := {0,0})
  60. begin
  61.     global kGestaltNoErr;
  62.     global kGestaltUnknownErr;
  63.     global kGestaltUndefSelectorErr;
  64.  
  65.     gesErr := GestaltGetError(gestaltAnswer);
  66.  
  67.     if gesErr = kGestaltNoErr
  68.         return "No error";
  69.  
  70.     if gesErr = kGestaltUnknownErr
  71.         return "Error: Could not obtain response";
  72.  
  73.     if gesErr = kGestaltUndefSelectorErr
  74.         return "Error: Undefined selector";
  75.  
  76.     return "Error: Unknown error code: {gesErr}";
  77. end;
  78.  
  79. (************************************************************************************
  80. * Task IsGestaltLongError(gestaltLongErr)
  81. *    Will check a list of known Long Error responses to see if the string passed
  82. *    is in fact an error.
  83. ************************************************************************************)
  84. task IsGestaltLongError(gestaltLongErr := "No error")
  85. begin
  86.     if gestaltLongErr = /Error≈/
  87.         return true;
  88.     else
  89.         return false;
  90. end;
  91.  
  92. (************************************************************************************
  93. * Task GestaltGetValue(gestaltAnswer)
  94. *    Will return the high word and low word pair of a Gestalt response in 
  95. *    the form of a list.
  96. ************************************************************************************)
  97. task GestaltGetValue(gestaltAnswer := {0,0})
  98. begin
  99.     return gestaltAnswer[2];
  100. end;
  101.  
  102. (************************************************************************************
  103. * Task GestaltGetHiWord(gestaltAnswer)
  104. *    Will return the high word portion from the answer of a Gestalt response.
  105. ************************************************************************************)
  106. task GestaltGetHiWord(gestaltAnswer := {0,0})
  107. begin
  108.     return( GestaltGetValue(gestaltAnswer) >> 16 );
  109. end;
  110.  
  111. (************************************************************************************
  112. * Task GestaltGetLoWord(gestaltAnswer)
  113. *    Will return the low word portion from the answer of a Gestalt response.
  114. ************************************************************************************)
  115. task GestaltGetLoWord(gestaltAnswer := {0, 0})
  116. begin
  117.     return( GestaltGetValue(gestaltAnswer) & 0x0000FFFF );
  118. end;
  119.  
  120. (************************************************************************************
  121. * All of the following tasks take the form GetGestaltXXX().  Their names
  122. *    are parallel to the gestaltXXX selectors as defined in InsideMacintosh
  123. *    Volume VI.  For instance the selector defined as the variable
  124. *    gestaltAddressingModeAttr has the equivalent VU task defined as
  125. *    GetGestaltAddressingModeAttr.
  126. * These tasks will return either a string representing a response, a string
  127. *    with the prefix "unkn" if a good response was returned but unrecognized
  128. *    by the tasks, or an error message string.  The only exceptions to this are
  129. *    the GetGestaltLogicalRAMSize and GetGestaltPhysicalRAMSize which will
  130. *    return integers instead of strings.
  131. ************************************************************************************)
  132.  
  133. (************************************************************************************
  134. * Task GetGestaltAddressingModeAttr()
  135. *    Will return the state of 32Bit addressing.
  136. ************************************************************************************)
  137. task GetGestaltAddressingModeAttr()
  138. begin
  139.     gesAns := Gestalt('addr');
  140.     gesErr := GestaltGetError(gesAns);
  141.     if (not gesErr)
  142.     begin
  143.         addrReturnVal := "";
  144.         addrAns := GestaltGetValue(gesAns);
  145.         if addrAns & (1 << 0)
  146.             addrReturnVal := addrReturnVal + "32BitAddressing ";
  147.         if addrAns & (1 << 1)
  148.             addrReturnVal := addrReturnVal +  "32BitSysZone ";
  149.         if addrAns & (1 << 2)
  150.             addrReturnVal := addrReturnVal +  "32BitCapable ";
  151.         if not ((addrAns & (1 << 0)) or (addrAns & (1 << 1)) or (addrAns & (1 << 2)))
  152.             addrReturnVal := addrReturnVal +  "unknAddressingModeAttr";
  153.         return addrReturnVal;
  154.     end;
  155.     else
  156.         return GestaltGetLongError(gesAns);
  157. end;
  158.  
  159. (************************************************************************************
  160. * Task GetGestaltEasyAccessAttr()
  161. *    Will return the current attributes to the Easy Access settings.  Note that
  162. *    the values returned by the gestalt call and the interpretation of these as
  163. *    described in Inside Macintosh Volume VI do not match.  If EasyAccess is not
  164. *    turned on in any way on the target, an "Undefined Selector" string will be 
  165. *    returned.  If EasyAccess is active, the "EasyPresent" value is returned.
  166. ************************************************************************************)
  167. task GetGestaltEasyAccessAttr()
  168. begin
  169.     gesAns := Gestalt('easy');
  170.     gesErr := GestaltGetError(gesAns);
  171.     if (not gesErr)
  172.     begin
  173.         easyReturnVal := "";
  174.         easyAns := GestaltGetValue(gesAns);
  175.         if easyAns & (1 << 0)
  176.             easyReturnVal := easyReturnVal + "EasyPresent ";
  177.         if easyAns & (1 << 1)
  178.             easyReturnVal := easyReturnVal + "EasyOn ";
  179.         if easyAns & (1 << 2)
  180.             easyReturnVal := easyReturnVal + "EasySticky ";
  181.         if easyAns & (1 << 3)
  182.             easyReturnVal := easyReturnVal + "EasyLocked ";
  183.         if not ((easyAns & (1 << 0)) or (easyAns & (1 << 1)) or (easyAns & (1 << 2)) or (easyAns & (1 << 3)))
  184.             easyReturnVal := easyReturnVal + "unknEasyAccess";
  185.         return easyReturnVal;
  186.     end;
  187.     else
  188.         return GestaltGetLongError(gesAns);
  189. end;
  190.  
  191. (************************************************************************************
  192. * Task GetGestaltFPUType()
  193. *    Will return the type of floating point coprocessor on the target.
  194. ************************************************************************************)
  195. task GetGestaltFPUType()
  196. begin
  197.     gesAns := Gestalt('fpu ');
  198.     gesErr := GestaltGetError(gesAns);
  199.     if (not gesErr)
  200.     begin
  201.         fpuAns := GestaltGetValue(gesAns);
  202.  
  203.         if fpuAns = 0
  204.             return "NoFPU";
  205.  
  206.         if fpuAns = 1
  207.             return "68881";
  208.  
  209.         if fpuAns = 2
  210.             return "68882";
  211.  
  212.         if fpuAns = 3
  213.             return "68040FPU";
  214.             
  215.         return "unknFPU";
  216.     end;
  217.     else
  218.         return GestaltGetLongError(gesAns);
  219. end;
  220.  
  221. (************************************************************************************
  222. * Task GetGestaltKeyboardType()
  223. *    Will return the type of keyboard in use on the target.
  224. ************************************************************************************)
  225. task GetGestaltKeyboardType()
  226. begin
  227.     gesAns := Gestalt('kbd ');
  228.     gesErr := GestaltGetError(gesAns);
  229.     if (not gesErr)
  230.     begin
  231.         kbdAns := GestaltGetValue(gesAns);
  232.  
  233.         if kbdAns = 1
  234.             return "MacKbd";
  235.  
  236.         if kbdAns = 2
  237.             return "MacKbdAndPad";
  238.  
  239.         if kbdAns = 3
  240.             return "MacPlusKbd";
  241.  
  242.         if kbdAns = 4
  243.             return "ExtADBKbd";
  244.  
  245.         if kbdAns = 5
  246.             return "StdADBKbd";
  247.  
  248.         if kbdAns = 6
  249.             return "PrtblADBKbd";
  250.  
  251.         if kbdAns = 7
  252.             return "PrtblISOKbd";
  253.  
  254.         if kbdAns = 8
  255.             return "StdISOADBKbd";
  256.  
  257.         if kbdAns = 9
  258.             return "ExtISOADBKbd";
  259.  
  260.         if kbdAns = 10
  261.             return "ADBKbdII";
  262.  
  263.         if kdbAns = 11
  264.             return "ADBISOKbdII";
  265.  
  266.         return "unknKbd";
  267.     end;
  268.     else
  269.         return GestaltGetLongError(gesAns);
  270. end;
  271.  
  272. (************************************************************************************
  273. * Task GetGestaltLogicalRAMSize()
  274. *    Will return the logical amount of RAM on the target.  This is a combination
  275. *    of physical RAM and virtual memory.  This value is an integer of the amount
  276. *    of memory in megabytes.
  277. ************************************************************************************)
  278. task GetGestaltLogicalRAMSize()
  279. begin
  280.     gesAns := Gestalt('lram');
  281.     gesErr := GestaltGetError(gesAns);
  282.     if (not gesErr)
  283.     begin
  284.         theHiWord := GestaltGetHiWord(gesAns);
  285.         # Gestalt apparently has a problem reporting the full 8MB of physical memory
  286.         # on machines with no virtual memory enabled.  This will compensate.
  287.         return (theHiWord + 1) / 16;
  288.     end;
  289.     else
  290.         return GestaltGetLongError(gesAns);
  291. end;
  292.  
  293. (************************************************************************************
  294. * Task GetGestaltMachineType()
  295. *    Will return the type of machine the target is.
  296. *    NOTE:  the value "Classic" does not refer to the modern Macintosh 
  297. *    Classic, but rather to the original Macintosh.  The newer model is
  298. *    referenced by the machine name "MacClassic".  This phrasing was used
  299. *    to stay consistent with the values referenced in Inside Macintosh VI
  300. *    and MPW include files.  Note also that the Macintosh Classic II model
  301. *    is referred to as "ClassicII" by the task.
  302. *    This list was last updated 03/15/96.
  303. ************************************************************************************)
  304. task GetGestaltMachineType()
  305. begin
  306.     gesAns := Gestalt('mach');
  307.     gesErr := GestaltGetError(gesAns);
  308.     if (not gesErr)
  309.     begin
  310.         machAns := GestaltGetLoWord(gesAns);
  311.         
  312.         switch( machAns )
  313.         begin
  314.             case 1:
  315.                 return "Classic";
  316.             case 2:
  317.                 return "MacXL";
  318.             case 3:
  319.                 return "Mac512KE";
  320.             case 4:
  321.                 return "MacPlus";
  322.             case 5:
  323.                 return "MacSE";
  324.             case 6:
  325.                 return "MacII";
  326.             case 7:
  327.                 return "MacIIx";
  328.             case 8:
  329.                 return "MacIIcx";
  330.             case 9:
  331.                 return "MacSE030";
  332.             case 10:
  333.                 return "Portable";
  334.             case 11:
  335.                 return "MacIIci";
  336.             case 13:
  337.                 return "MacIIfx";
  338.             case 17:
  339.                 return "MacClassic";
  340.             case 18:
  341.                 return "MacIIsi";
  342.             case 19:
  343.                 return "MacLC";
  344.             case 20:
  345.                 return "Quadra900";
  346.             case 21:
  347.                 return "Powerbook170";
  348.             case 22:
  349.                 return "Quadra700";
  350.             case 23:
  351.                 return "ClassicII";
  352.             case 24:
  353.                 return "PowerBook100";
  354.             case 25:
  355.                 return "PowerBook140";
  356.                 
  357.             case 26:
  358.                 return "Quadra950";
  359.             case 27:
  360.                 return "MacLCIII";
  361.             case 29:
  362.                 return "PowerBookDuo210";
  363.             case 30:
  364.                 return "MacCentris650";
  365.             case 32:
  366.                 return "PowerBookDuo230";
  367.             case 33:
  368.                 return "PowerBook180";
  369.             case 34:
  370.                 return "PowerBook160";
  371.             case 35:
  372.                 return "MacQuadra800";
  373.             case 36:
  374.                 return "MacQuadra650";
  375.             case 37:
  376.                 return "MacLCII";
  377.             case 38:
  378.                 return "PowerBookDuo250";
  379.             case 39:
  380.                 return "AWS9150_80";
  381.             case 40:
  382.                 return "PowerMac8100_110";
  383.             case 41:
  384.                 return "PowerMac5200";
  385.             case 42:
  386.                 return "PowerMac6200";
  387.             case 44:
  388.                 return "MacIIvi";
  389.             case 45:
  390.                 return "MacIIvm";
  391.             case 47:
  392.                 return "PowerMac7100_80";
  393.             case 48:
  394.                 return "MacIIvx";
  395.             case 49:
  396.                 return "MacColorClassic";
  397.             case 50:
  398.                 return "PowerBook165c";
  399.             case 52:
  400.                 return "MacCentris610";
  401.             case 53:
  402.                 return "MacQuadra610";
  403.             case 54:
  404.                 return "PowerBook145";
  405.             case 55:
  406.                 return "PowerMac8100_100";
  407.             case 56:
  408.                 return "MacLC520";
  409.             case 57:
  410.                 return "AWS9150_120";
  411.             case 60:
  412.                 return "MacCentris660AV";
  413.             case 62:
  414.                 return "Performa46x";
  415.             case 65:
  416.                 return "PowerMac8100_80";
  417.             case 67:
  418.                 return "PowerMac9500";
  419.             case 68:
  420.                 return "PowerMac7500";
  421.             case 69:
  422.                 return "PowerMac8500";
  423.             case 71:
  424.                 return "PowerBook180c";
  425.             case 72:
  426.                 return "PowerBook5x0";
  427.             case 75:
  428.                 return "PowerMac6100_60";
  429.             case 77:
  430.                 return "PowerBookDuo270c";
  431.             case 78:
  432.                 return "MacQuadra840AV";
  433.             case 80:
  434.                 return "Performa550";
  435.             case 84:
  436.                 return "PowerBook165";
  437.             case 85:
  438.                 return "PowerBook190";
  439.             case 88:
  440.                 return "MacTV";
  441.             case 89:
  442.                 return "MacLC475";
  443.             case 92:
  444.                 return "MacLC575";
  445.             case 94:
  446.                 return "MacQuadra605";
  447.             case 98:
  448.                 return "Quadra630";
  449.             case 100:
  450.                 return "PowerMac6100_66";
  451.             case 102:
  452.                 return "PowerBookDuo280";
  453.             case 103:
  454.                 return "PowerBookDuo280c";
  455.             case 108:
  456.                 return "PowerMac7200";
  457.             case 112:
  458.                 return "PowerMac7100_66";
  459.             case 115:
  460.                 return "PowerBook150";
  461.             case 124:
  462.                 return "PowerBookDuo2300";
  463.             case 126:
  464.                 return "PowerBook500PPCUpgrade";
  465.             case 128:
  466.                 return "PowerBook5300";
  467.     
  468.             default:
  469.                 return "unknMachineType";
  470.         end;
  471.     end;
  472.     else
  473.         return GestaltGetLongError(gesAns);
  474. end;
  475.  
  476. (************************************************************************************
  477. * Task GetGestaltMMUType()
  478. *    Will return the memory management unit type found operating on the target.
  479. ************************************************************************************)
  480. task GetGestaltMMUType()
  481. begin
  482.     gesAns := Gestalt('mmu ');
  483.     gesErr := GestaltGetError(gesAns);
  484.     if (not gesErr)
  485.     begin
  486.         mmuAns := GestaltGetValue(gesAns);
  487.  
  488.         if mmuAns = 0
  489.             return "NoMMU";
  490.  
  491.         if mmuAns = 1
  492.             return "AMU";
  493.  
  494.         if mmuAns = 2
  495.             return "68851";
  496.  
  497.         if mmuAns = 3
  498.             return "68030MMU";
  499.  
  500.         if mmuAns = 4
  501.             return "68040MMU";
  502.  
  503.         return "unknMMUType";
  504.     end;
  505.     else
  506.         return GestaltGetLongError(gesAns);
  507. end;
  508.  
  509. (************************************************************************************
  510. * Task GetGestaltPhysicalRAMSize()
  511. *    Will return the amount of physical RAM located in a machine.  This value is
  512. *    an integer in megabytes.
  513. ************************************************************************************)
  514. task GetGestaltPhysicalRAMSize()
  515. begin
  516.     gesAns := Gestalt('ram ');
  517.     gesErr := GestaltGetError(gesAns);
  518.     if (not gesErr)
  519.     begin
  520.         theHiWord := GestaltGetHiWord(gesAns);
  521.         # Gestalt apparently has a problem reporting the full 8MB of physical memory
  522.         # on machines with no virtual memory enabled.  This will compensate.
  523.         return (theHiWord + 1) / 16;
  524.     end;
  525.     else
  526.         return GestaltGetLongError(gesAns);
  527. end;
  528.  
  529. (************************************************************************************
  530. * Task GetGestaltProcessorType()
  531. *    Will return the type of microprocessor running in the target machine.
  532. ************************************************************************************)
  533. task GetGestaltProcessorType()
  534. begin
  535.     gesAns := Gestalt('proc');
  536.     gesErr := GestaltGetError(gesAns);
  537.     if (not gesErr)
  538.     begin
  539.         procAns := GestaltGetValue(gesAns);
  540.         
  541.         switch( procAns )
  542.         begin
  543.             case 1:
  544.                 return "68000";
  545.             case 2:
  546.                 return "68010";
  547.             case 3:
  548.                 return "68020";
  549.             case 4:
  550.                 return "68030";
  551.             case 5:
  552.                 return "68040";
  553.             default:
  554.                 return "unknProc";
  555.         end;
  556.     end;
  557.     else
  558.         return GestaltGetLongError(gesAns);
  559. end;
  560.  
  561. (************************************************************************************
  562. * Task GetGestaltVMAttr()
  563. *    Will return the state of virtual memory on the target machine.
  564. ************************************************************************************)
  565. task GetGestaltVMAttr()
  566. begin
  567.     gesAns := Gestalt('vm  ');
  568.     getErr := GestaltGetError(gesErr);
  569.     if (not gesErr)
  570.     begin
  571.         vmAns := GestaltGetValue(gesAns);
  572.         if vmAns & (1 << 0)
  573.             return "VMPresent";
  574.         if not (vmAns & (1 << 0))
  575.             return "unknVMAttr";
  576.     end;
  577.     else
  578.         return GestaltGetLongError(gesAns);
  579. end;